﻿package mortal.game.view.copy.ZZXYBattle
{
    import Message.Public.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.data.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.*;
    import mortal.game.view.copy.QuestionCopy.data.*;
    import mortal.game.view.copy.sixBoss.data.*;
    import mortal.game.view.mainUI.smallMap.view.*;

    public class ZZXYBattleInfoPanel extends CopyInfoPanelBase
    {
        private var _bg:GImageBitmap;
        private var _leftTime:SecTimerView;
        private var _smallMap:SmallMapEmbedView;
        private var _txtMyScore:GTextFiled;
        private var _ranks:GTileList;
        private var _bmpDrop:GImageBitmap;

        public function ZZXYBattleInfoPanel()
        {
            super(ImagesConst.copyInfoPanelTitle_ZZXYBattle, 250, 580);
            return;
        }// end function

        public function updateLeftTime() : void
        {
            var _loc_2:int = 0;
            var _loc_1:* = ZZXYBattleController.openData;
            if (_loc_1 == null)
            {
                this._leftTime.setLeftTime(900);
            }
            else
            {
                _loc_2 = (_loc_1.endDt.time - ClockManager.instance.nowDate.time) / 1000;
                this._leftTime.setLeftTime(_loc_2);
            }
            return;
        }// end function

        public function updateSelfScore(param1:int) : void
        {
            this._txtMyScore.text = param1.toString();
            return;
        }// end function

        private function updateOutputList() : void
        {
            var _loc_5:SixBossOutPutRewardInfo = null;
            var _loc_1:* = QuestionCopyConfig.instance().getRewardsByTypeAndTimes(7, 0);
            var _loc_2:Array = [];
            var _loc_3:int = 0;
            while (_loc_3 < _loc_1.length)
            {
                
                _loc_5 = new SixBossOutPutRewardInfo();
                _loc_5.outPutIndex = _loc_3 + 1;
                _loc_5.itemCode = int(_loc_1[_loc_3].split("#")[0]);
                _loc_5.itemAmount = int(_loc_1[_loc_3].split("#")[1]);
                _loc_2.push(_loc_5);
                _loc_3++;
            }
            var _loc_4:* = new DataProvider();
            _loc_4.addItems(_loc_2);
            return;
        }// end function

        public function updateRankList(param1:Array) : void
        {
            var _loc_7:SPeaceBossPlayer = null;
            var _loc_8:ZZXYBattleRankData = null;
            if (isDisposed)
            {
                return;
            }
            var _loc_2:* = new DataProvider();
            var _loc_3:int = 0;
            while (_loc_3 < param1.length)
            {
                
                _loc_7 = param1[_loc_3] as SPeaceBossPlayer;
                _loc_8 = new ZZXYBattleRankData();
                _loc_8.player = _loc_7;
                _loc_2.addItem(_loc_8);
                _loc_3++;
            }
            _loc_2.sort(this.sortData);
            var _loc_4:* = QuestionCopyConfig.instance().getRewardInfoByTypeAndScoreMax(4, 1);
            var _loc_5:* = QuestionCopyConfig.instance().getRewardInfoByTypeAndScoreMax(4, 3);
            var _loc_6:* = QuestionCopyConfig.instance().getRewardInfoByTypeAndScoreMax(4, 10);
            _loc_3 = 0;
            while (_loc_3 < _loc_2.length)
            {
                
                _loc_8 = _loc_2.getItemAt(_loc_3) as ZZXYBattleRankData;
                if (_loc_3 == 0)
                {
                    _loc_8.rewards = this.parseRewardData(_loc_4);
                }
                else if (_loc_3 <= 2)
                {
                    _loc_8.rewards = this.parseRewardData(_loc_5);
                }
                else
                {
                    _loc_8.rewards = this.parseRewardData(_loc_6);
                }
                _loc_8.rank = _loc_3 + 1;
                _loc_3++;
            }
            this._ranks.dataProvider = _loc_2;
            this._ranks.drawNow();
            return;
        }// end function

        private function parseRewardData(param1:Object) : Array
        {
            var _loc_6:Array = null;
            var _loc_7:SReward = null;
            var _loc_2:Array = [];
            if (param1 == null)
            {
                return _loc_2;
            }
            var _loc_3:* = param1["itemRewards"];
            if (_loc_3 == null || _loc_3 == "")
            {
                return _loc_2;
            }
            var _loc_4:* = _loc_3.split("&");
            var _loc_5:int = 0;
            while (_loc_5 < _loc_4.length)
            {
                
                _loc_3 = _loc_4[_loc_5];
                if (_loc_3 == null || _loc_3.length < 2)
                {
                }
                else
                {
                    _loc_6 = _loc_3.split("#");
                    _loc_7 = new SReward();
                    _loc_7.code = parseInt(_loc_6[0]);
                    _loc_7.num = parseInt(_loc_6[1]);
                    _loc_7.type = EReward._ERewardItem;
                    _loc_2.push(_loc_7);
                }
                _loc_5++;
            }
            return _loc_2;
        }// end function

        private function sortData(param1:ZZXYBattleRankData, param2:ZZXYBattleRankData) : int
        {
            if (param1.player.score < param2.player.score)
            {
                return 1;
            }
            return -1;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.gImageBitmap(null, 0, 0, _bodySprite);
            LoaderHelp.setBitmapdata(ImagesConst.ZZXYBattleRankBg + ".swf", this._bg);
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(20980), 39, 13, 100, 20, _bodySprite, GlobalStyle.textFormatHuang));
            this._leftTime = UIFactory.secTimeView(Language.getString(20981), 101, 13, 120, 22, _bodySprite, GlobalStyle.textFormatHong.right());
            this._leftTime.timeOutHandler = this.timerOutHandler;
            this._leftTime.filters = [FilterConst.glowFilter];
            this._smallMap = UIFactory.smallMapEmbedView(ImagesConst.ZZXYBattleMiniMap, 11, 41, _bodySprite, true);
            this._smallMap.run();
            this._bmpDrop = UIFactory.gImageBitmap(ImagesConst.ZZXYBattleLabel, 11, 207, _bodySprite);
            var _loc_1:* = GlobalStyle.textFormatLv;
            _loc_1.color = 65280;
            pushUIToDisposeVec(UIFactory.gTextField(Language.getString(20982), 31, 553, 220, 22, _bodySprite, _loc_1.clone()));
            this._txtMyScore = UIFactory.gTextField("0", 125, 553, 220, 22, _bodySprite, _loc_1.clone());
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(20983), 33, 286, 100, 20, _bodySprite, GlobalStyle.textFormatBai));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(20984), 108, 286, 100, 20, _bodySprite, GlobalStyle.textFormatBai));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(20985), 195, 286, 100, 20, _bodySprite, GlobalStyle.textFormatBai));
            this._ranks = UIFactory.tileList(11, 307, 236, 280, _bodySprite);
            this._ranks.setStyle("cellRenderer", ZZXYBattleRankRender);
            this._ranks.verticalGap = 1;
            this._ranks.rowHeight = 24;
            this._ranks.columnWidth = 202;
            this.updateLeftTime();
            return;
        }// end function

        private function checkRewardsGot(param1) : void
        {
            GameController.copy.ZZXYBattle.rewardModule.show();
            return;
        }// end function

        private function timerOutHandler() : void
        {
            if (isDisposed)
            {
                return;
            }
            this._leftTime.stop();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._bg.dispose(param1);
            this._bg = null;
            this._leftTime.dispose(param1);
            this._leftTime = null;
            this._smallMap.dispose(param1);
            this._smallMap = null;
            this._txtMyScore.dispose(param1);
            this._txtMyScore = null;
            this._ranks.dispose(param1);
            this._ranks = null;
            this._bmpDrop.dispose(param1);
            this._bmpDrop = null;
            return;
        }// end function

    }
}
